package com.project.myproject;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Honorable(mabingqian)
 * @description
 * @date 2020/8/5 16:54
 * @update （更新、优化，注明点）
 */
public class DataTest {
    public static void main(String[] args) throws Exception {

        String str = "{\n" +
                "    \"headers\": \"ezoUserid:EZO-UserId,mobile:EZO-Phone,appKey:EZO-AppKey,loginName:EZO-UserName,envUserId:EZO-EnvUserId,corpId:EZO-CorpId,unionId:EZO-UnionId,userType:EZO-UserType\",\n" +
                "    \"bodys\": \"\"\n" +
                "}";
        System.out.println(getLastDayMorning());
        System.out.println(getLastDayNight());
    }

    /**
     * 获得前一天 0 点日期（String)
     * @return
     */
    public static String getLastDayMorning() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);
        Date time = cal.getTime();
        return sdf.format(time);
    }

    /**
     * 获得前一天 24 点日期（String) 也就是当天0点日期
     * @return
     */
    public static String getLastDayNight() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 0);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);
        Date time = cal.getTime();
        return sdf.format(time);
    }
}
